home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / prompt.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  3KB  |  88 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        prompt.c
  13.  * Purpose:     prompt for and receive GFFT command string
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     29-May-1993 CPP; Created.
  16.  * Comments:
  17.  *              (1) Just to be nice, I'm considering EOF as an acceptable
  18.  *              way to terminate gfft.  If it is preceded by a command on
  19.  *              the same line, that is allowed to complete first.
  20.  *              However, if DEBUG is defined, a message will be displayed
  21.  *              on the detection of EOF.  (I seem to get EOF's for some
  22.  *              reason when debugging.  Don't understand it yet.)
  23.  *
  24.  *              (2) Currently commands are quite limited in length
  25.  *              inherently, so a limited buffer is quite OK.  Sure,
  26.  *              it takes a few static bytes, but who's perfect?  If
  27.  *              ever commands are allowed to get much larger I'll make it
  28.  *              dynamic, but now that seems like overdoing it in view of
  29.  *              how difficult C makes dealing with dynamic strings.
  30.  *
  31.  *              (3) However, I'm not going to let an excessively long
  32.  *              command overwrite any other program data.  That's why
  33.  *              this function is a little more tedious than it might
  34.  *              be if I used 'gets' or 'scanf'.
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include <dos/dosasl.h>  /* _OSERR */
  39. #include <error.h>       /* errno */
  40.  
  41. #include "gfft.h"
  42.  
  43. void prompt_command (void)
  44. {
  45.     static int iclosed = FALSE;
  46.     int icharacter = 0;
  47.     int i;
  48.  
  49.     if (iclosed)
  50.     {
  51.     gabort (EXIT_SUCCESS);
  52.     }
  53.     printf ("%s",PROMPT);
  54.  
  55.     for (i=0; i < COMMAND_BUFFER_SIZE-1; i++)
  56.     {
  57.     icharacter = getc (stdin);
  58.     if (icharacter == EOF)
  59.     {
  60.  
  61. #ifdef _DEBUG
  62.         fprintf (stderr,"\nerrno = %d; _OSERR = %d\n", errno, _OSERR);
  63. #endif
  64.  
  65.         if (i <= 0)     /* error or EOF; shouldn't usually happen */
  66.         {
  67.         gabort (EXIT_SUCCESS);
  68.         }
  69.         else            /* Command termined by EOF; exit on next call */
  70.         {
  71.         iclosed = TRUE;
  72.         Command[i] = '\0';
  73.         break;
  74.         }
  75.     }
  76.     else if (icharacter == '\n')
  77.     {
  78.         Command[i] = '\0';
  79.         break;
  80.     }
  81.     else
  82.     {
  83.         Command[i] = (char) icharacter;
  84.     }
  85.     }
  86. }
  87.  
  88.